package com.example.service;

import com.example.entity.MonitoringSite;
import com.example.mapper.MonitoringSiteMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

@Service
public class MonitoringSiteService {
    private final MonitoringSiteMapper monitoringSiteMapper;

    public MonitoringSiteService(MonitoringSiteMapper monitoringSiteMapper) {
        this.monitoringSiteMapper = monitoringSiteMapper;
    }

    public List<MonitoringSite> getAllSites() {
        return monitoringSiteMapper.selectAll();
    }

    public MonitoringSite getSiteById(Integer id) {
        return monitoringSiteMapper.selectById(id);
    }

    @Transactional
    public boolean addSite(MonitoringSite site) {
        if (site.getStatus() == null) {
            site.setStatus("online");
        }
        return monitoringSiteMapper.insert(site) > 0;
    }

    @Transactional
    public boolean updateSite(MonitoringSite site) {
        return monitoringSiteMapper.update(site) > 0;
    }

    @Transactional
    public boolean deleteSite(Integer id) {
        return monitoringSiteMapper.deleteById(id) > 0;
    }

    public List<MonitoringSite> getSitesByRoomId(Integer roomId) {
        return monitoringSiteMapper.selectByRoomId(roomId);
    }
} 